﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace IESN.MyControl
{
    public partial class NumericTextBox : TextBox
    {
        private bool blnHaveMinus;
        private bool blnHavepoint;
        private IContainer components;

        public NumericTextBox()
        {
            base.KeyPress += new KeyPressEventHandler(this.NumericTextBox_KeyPress);
            this.blnHaveMinus = true;
            this.blnHavepoint = true;
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        //[DebuggerStepThrough]
        private void InitializeComponent()
        {
            this.components = new Container();
        }

        private void NumericTextBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            int num = (short)e.KeyChar;
            int num2 = num;
            if (((num2 < 0x30) || (num2 > 0x39)) && ((num2 != 8) && (num2 != 13)))
            {
                if (num2 == 0x2d)
                {
                    if (this.blnHaveMinus)
                    {
                        if (string.Equals(this.Text, "-", StringComparison.CurrentCultureIgnoreCase))
                        {
                            num = 0;
                        }
                        if (this.SelectionStart != 0)
                        {
                            num = 0;
                        }
                    }
                    else
                    {
                        num = 0;
                    }
                }
                else if (num2 == 0x2e)
                {
                    if (this.HavePoint)
                    {
                        if (string.Equals(this.Text, ".", StringComparison.CurrentCultureIgnoreCase))
                        {
                            num = 0;
                        }
                    }
                    else
                    {
                        num = 0;
                    }
                }
                else
                {
                    num = 0;
                }
            }
            if (num == 0)
            {
                e.Handled = true;
            }
            else
            {
                e.Handled = false;
            }
        }

        public bool haveMinus
        {
            get
            {
                return this.blnHaveMinus;
            }
            set
            {
                this.blnHaveMinus = value;
            }
        }

        public bool HavePoint
        {
            get
            {
                return this.blnHavepoint;
            }
            set
            {
                this.blnHavepoint = value;
            }
        }
    }
}
